<template>
	<view class="" style="width: 750upx;height: 100vh;background-color: rgb(241, 241, 241)">
		<view class="" style="width: 100upx;height: 10upx;">
			
		</view>
		<view class="" style="background-color: white;width: 650upx;margin: 30upx;border-radius: 10upx;padding: 40upx 20upx;">
			
		
			<radio-group @change="radioDizhi" style="background-color: white;">
				<view class="" v-for="(item,index) in addressAllForUser">
					<view class="" style="display: flex;align-items: center;justify-content: space-between;">
						<view class="" style="display: flex;align-items: center;" @longpress="shangchu(item.addressId)">
							<radio :value="index"  :checked="index === current"  color="rgb(25,137,250)"/>
							<view class="" style="margin-top: 20upx;margin-left: 20upx;">
								
								<view class="" style="display: flex;font-weight: bold;">
									<view class="">
										{{item.nickName}}
									</view>
									<view class="" style="margin-left: 20upx;">
										{{item.phone}}
									</view>
									
								</view>
								<view class="" style="font-size: 26upx;">
									{{item.province}} {{item.city}} {{item.area}} {{item.detail}}
								</view>
							</view>
						</view>
						<navigator :url="'/pages/packageUserCenter/addAddress/index?addressId='+item.addressId+'&&data='+JSON.stringify(item)">
							<uni-icons type="compose" color="rgb(33,33,33)" size="30"></uni-icons>
						</navigator>
						
					</view>
				</view>
			</radio-group>
		</view>
		<view class="" style="margin-top: 140upx;">
			
		</view>
		<view class="quedingView">
			<navigator url="/pages/packageUserCenter/addAddress/index" class="btnView">
				添加
			</navigator>
			<view class="btnView" @click="quedingBTM">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressAllForUser:"",
				adIndex:-1,
			}
		},
		onLoad(options) {
			
		},
		onShow() {
			
					this.addressAllForUserFC()
		},
			
		methods:{
			addressAllForUserFC: async function(){
				const addressAllForUser = await this.$ajax.addressAllForUser({
					pageNum: 1,
					pageSize: 50
				})
				this.addressAllForUser=addressAllForUser.data.data
			
				console.log("addressAllForUser",this.addressAllForUser)
				
			
			},
			radioDizhi(e){
				// console.log(e.detail.value)
				this.adIndex=e.detail.value
			},
			shangchu(id){
				var that=this
				uni.showModal({
					content: '是否要删除该地址？',
					success: function (res) {
						if (res.confirm) {
							that.addressDelFC(id)
						} 
					}
				});
			},
			addressDelFC: async function(id){
				const addressDel = await this.$ajax.addressDel({
					addressId: id
				})
				console.log(addressDel)
				if(addressDel.data.code==200){
					this.addressAllForUserFC()
				}
			},
			quedingBTM(){
				if(this.adIndex==-1){
					uni.showToast({
						title:"请选择一个地址",
						icon:"none",
						duration:1000
					})
				}else{
					const pages = getCurrentPages()//获取所有实例
					const previousPageS = pages[pages.length-2]//当前页面的上一个页面
					// previousPageS.$vm.roomEntityList[this.isFangjianIndex].roomProductList=this.roomProductList
					
					uni.navigateBack({
						delta:1
					})
					previousPageS.$vm.addressData=this.addressAllForUser[this.adIndex]
				}
			}
			
		}
	}
</script>

<style>
	.quedingView{
		position: fixed;
		width: 630upx;
		bottom:0upx;
		height: 100upx;
		background-color: white;
		padding: 0 60upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.btnView{
		padding: 6.5px 0 6.5px;
		background-image: linear-gradient(-34deg, #106bf3 0%, #00c0fa 100%);
		box-shadow: 1.5px 2px 15.5px #0d70f31a;
		border-radius: 5px;
		width: 99.5px;
		height: 23.5px;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: bold;
	}
</style>